﻿using UnityEngine;

public class CameraMovieMgr
{
    private TweenPRS mTween;
    private Quaternion mR;
    private Vector3 mP;
    private Vector3 mS;

    public CameraMovieMgr()
    {
        mP = new Vector3(); mR = new Quaternion(); mS = new Vector3();
        ZEventCenter.AddEventListener(ConstData.SCENE_LOAD_END, OnSceneLoaded);
    }

    private void OnSceneLoaded(ZEvent ev)
    {
        GameObject mCamera = ZMgr.UIMgr.MainCam;
        mTween = UITweener.Begin<TweenPRS>(mCamera, 0.6f);
        mTween.enabled = false;
    }

    /// <summary>
    /// 播放镜头动画
    /// </summary>
    /// <param name="id">镜头动画模板id</param>
    public void PlayMovie(int id)
    {
        var dbvo = TableDataMgr.CameraMoveMgr.GetItemById(id);
        if (dbvo == null) { return; }

        mP.Set(dbvo.Px, dbvo.Py, dbvo.Pz);
        mR.Set(dbvo.Rx, dbvo.Ry, dbvo.Rz, dbvo.Rw);
        mS.Set(dbvo.Sx, dbvo.Sy, dbvo.Sz);

        mTween.SetTo(mP, mR, mS);
        mTween.ResetToBeginning();
        mTween.enabled = true;
    }
}